package jwebtester.business.beans.competencies;

import infrastructure.Scopes;

import java.util.List;

import jwebtester.business.services.SessionMapService;
import jwebtester.dal.provider.CompetenciesDataProvider;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import domain.entities.Competency;

@Component
@Scope(Scopes.Request)
public class AutocompleteCompetencyBean {
	
	private static final Logger LOG = LoggerFactory.getLogger(AutocompleteCompetencyBean.class);

	@Autowired
	private transient CompetenciesDataProvider dataProvider;

	@Autowired
	private transient SessionMapService sessionService;

	public List<Competency> completeCompetencies(final String query) {
		final int organizationID = sessionService.getCurrentOrganizationID();
		final List<Competency> competencies = dataProvider.getCompetencies(organizationID, query);
		
		LOG.trace(String.format("Found [%s] competencies for autocomplete", competencies.size()));
		
		return competencies;
	}
}
